<?php
	
/**
 * 说明：
 *
 * @author  991<nomit@qq.com>
 * @date	2011-02-25
 *
 */
 



class SessionApi extends ApiBase{
	/**
	 * 构造函数，初始化插件
	 * 
	 */
	private $handle=NULL;
	private $key;//session存储块key
	public function __construct(){
		$this->key = 'session::list';
		$this->handle = n_api('redis')->c001;
		
	}
	public function start(){
		session_set_save_handler(array(&$this, 'open'),array(&$this, 'close'),array(&$this, 'read'),array(&$this, 'write'),array(&$this, 'destroy'),array(&$this, 'gc'));
		session_start();
		$_SESSION['stime'] = date("Y-m-d H:i:s");//最后访问时间
		
	}
	
	public function open(){return true;}
	public function close(){return true;}
	public function read($id){
		$sval = $this->handle->hmGetElment($this->key,array($id));
		return $sval[$id];
	}
	public function write($id,$val){$this->handle->hmSave($this->key,array($id=>$val));}
	public function destroy($id){$this->handle->hmDelete($this->key,$id);}
	public function gc($maxlifetime){}
}
